
*Dainn's Cleaning File made in grumpy mood

cd "C:\MyWorks\BIHS\BIHS"
*cd "G:\Dropbox\Work\BIHS\BIHS"

cap log close


use "BIHSRound3\Male\010_bihs_r3_male_mod_b1.dta", clear

gen year=2018
gen hid=int(a01)
rename b1_01 sex
rename b1_02 age
rename b1_16 binfo
rename b1_03 relation
rename b1_04 mstatus
rename b1_04a mage
rename b1_04b cage
rename b1_05 migration
rename b1_07 literacy
rename b1_08 education
rename b1_09 attend_school
rename b1_10 main_occ
rename b1_11 occ_urban
rename b1_12 occ_location
replace migration=0 if migration==2
replace attend_school=0 if attend_school!=1

gen adult=(age>=18)
by a01, sort: egen adultn=sum(adult)

gen yrsedu=.
replace yrsedu=0 if education==99 | education==66 | education==67 
replace yrsedu=1 if education==0 | education==1
replace yrsedu=2 if education==2
replace yrsedu=3 if education==3
replace yrsedu=4 if education==4
replace yrsedu=5 if education==5
replace yrsedu=6 if education==6
replace yrsedu=7 if education==7
replace yrsedu=8 if education==8
replace yrsedu=9 if education==9
replace yrsedu=10 if education==10
replace yrsedu=12 if education==12

replace yrsedu=16 if education==14 | education==15 | education==72 | education==73 | education==74
replace yrsedu=18 if education==16 | education==71 
replace yrsedu=10 if education==22
replace yrsedu=12 if education==33 | education==75


label var year "2011-2012, 2015, 2018-2019"
label var a01 "Household identification number"
label var hid "Unique household identification number"
label var mid "Member identification number"
label var sex "sex (1=-male 2=female)"
label var age "age of the member" 
label var binfo "source of BOD information"
label var mage "age at marriage"
label var cage "Age when first child born"
label var relation "relation to primary respondent"
label var mstatus "marital status of the member"
label var migration "migrated for more than 6m during last 5 yrs"
label var literacy "literacy of member (1=illiterate 2=can sign 3=read 4=literate)"
label var education "education of the member"
label var attend_school "currently attending school (1=yes)"
label var main_occ "current main occupation"
label var occ_urban "work in rural/urban 1=rural 2=urban"
label var occ_location "location of employment"
label var adult "indicator age 18 or older"
label var adultn "number of adults in households"
label var yrsedu "years of education" 


keep year hid a01 mid sex age binfo mage relation mstatus migration literacy education yrsedu mage attend_school main_occ occ_urban occ_location adult adultn

save "tmp_2018b1_male", replace


keep year a01 hid adultn
save "tmp_2018_hsize", replace



use "BIHSRound3\Male\012_bihs_r3_male_mod_c.dta", clear

gen year=2018
gen hid=int(a01)
rename  mid_c mid
rename c01 estatus
rename c05 occ
rename c06 aid
rename c07 dow 
rename c08 how
rename c09 etype
rename c10 wage
rename c11 wage_kind
rename c13 mincome

label var year "2011-2012, 2015, 2018-2019"
label var a01 "Household identification number"
label var hid "Unique household identification number"
label var mid "Member identification number"
label var estatus "employment status in past 7 days"
label var occ "occupation in last 7 days"
label var aid "activity serial no"
label var dow "days of work in last week"
label var how "average hours of work per day"
label var etype "nature of employment"
label var wage "daily wage in cash"
label var wage_kind "daily wage in kind"
label var mincome "montly income for self employment"

#delimit ;
keep year hid a01 mid estatus occ aid dow how etype wage wage_kind mincome
;
#delimit cr

by a01 mid, sort: gen act=_n
drop if act>3
drop aid
reshape wide estatus occ dow how etype wage wage_kind mincome, i(year hid a01 mid) j(act)
save "tmp_2018c_male", replace


clear
use "BIHSRound3\Male\067_bihs_r3_male_mod_t1b.dta"

gen year=2018
gen hid=int(a01)

rename t1b_01 shockNeg_code
rename t1b_02 shockNeg_shock2015
rename t1b_04 shockNeg_econ
rename t1b_05 shockNeg_food
rename t1b_06a shockNeg_copingstrategy1
rename t1b_06b shockNeg_copingstrategy2
rename t1b_06c shockNeg_copingstrategy3

#delimit ;
keep year hid a01 shockNeg_code-shockNeg_copingstrategy3 hh_type   
;
#delimit cr
drop t1b_03
label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number


label var shockNeg_code "Negative shock: shock code"
label var shockNeg_shock2015 "Negative shock: : occurrence (since 2015)"
label var shockNeg_econ "Negative shock: Impact of shock: economic condition"
label var shockNeg_food "Negative shock: Impact of shock: food consumption"
label var shockNeg_copingstrategy1 "Negative shock: (The last time) coping strategy 1"
label var shockNeg_copingstrategy2 "Negative shock: (The last time) coping strategy 2"
label var shockNeg_copingstrategy3 "Negative shock: (The last time) coping strategy 3"


by a01 , sort: gen act=_n
reshape wide shockNeg_code shockNeg_shock2015 shockNeg_econ shockNeg_food  shockNeg_copingstrategy1 shockNeg_copingstrategy2 shockNeg_copingstrategy3 , i(a01 year hid) j(act)

save "tmp_2018t1_male", replace


*Module T2: Positive shocks

clear
use "2011-2012\039_mod_t2_male.dta"


gen year=2011
gen hid=int(a01)

rename t2_02 shockPos_code
rename t2_03 shockPos_Experienced
rename t2_04 shockPos_month
rename t2_05 shockPos_year
rename t2_06 shockPos_value
rename t2_07 shockPos_rank

replace shockPos_Experienced = abs(2-shockPos_Experienced)

#delimit ;
keep year hid a01 shockPos_code-shockPos_rank 
;
#delimit cr

g shockPos_rank1 = (shockPos_rank==1)
g shockPos_rank2 = (shockPos_rank==2)
g shockPos_rank3 = (shockPos_rank==3)

label var year "2011-2012, 2015"
label var a01 "Household identification number"


label var shockPos_code "Positive shock: shock code"
label var shockPos_Experienced "Positive shock: Has any events (last 5 years)"
label var shockPos_month "Positive shock: (The last time) Month"
label var shockPos_year "Positive shock: (The last time) Year"
label var shockPos_value "Positive shock: (The last time) total value"
label var shockPos_rank "Positive shock: Rank the most important events"
label var shockPos_rank1 "Positive shock: most important events"
label var shockPos_rank2 "Positive shock: 2nd most important events"
label var shockPos_rank3 "Positive shock: 3rd most important events"

drop shockPos_rank

by a01 , sort: gen act=_n
reshape wide shockPos_code shockPos_Experienced shockPos_month shockPos_year shockPos_value  shockPos_rank1 shockPos_rank2 shockPos_rank3, i(a01 year hid) j(act)

save "tmp_2011t2_male", replace


clear
use "2015\051_r2_mod_t2_male.dta"


gen year=2015
gen hid=int(a01)

rename t2_02 shockPos_code
rename t2_03 shockPos_Experienced
rename t2_04 shockPos_month
rename t2_05 shockPos_year
rename t2_06 shockPos_value
rename t2_07 shockPos_rank

replace shockPos_Experienced = abs(2-shockPos_Experienced)


#delimit ;
keep year hid a01 shockPos_code-shockPos_rank hh_type
;
#delimit cr

g shockPos_rank1 = (shockPos_rank==1)
g shockPos_rank2 = (shockPos_rank==2)
g shockPos_rank3 = (shockPos_rank==3)

label var hh_type "type of sample survey"
label var year "2011-2012, 2015"
label var a01 "Household identification number"

label var shockPos_code "Positive shock: shock code"
label var shockPos_Experienced "Positive shock: Has any events (last 5 years)"
label var shockPos_month "Positive shock: (The last time) Month"
label var shockPos_year "Positive shock: (The last time) Year"
label var shockPos_value "Positive shock: (The last time) total value"
label var shockPos_rank "Positive shock: Rank the most important events"
label var shockPos_rank1 "Positive shock: most important events"
label var shockPos_rank2 "Positive shock: 2nd most important events"
label var shockPos_rank3 "Positive shock: 3rd most important events"

drop shockPos_rank

by a01 , sort: gen act=_n
reshape wide shockPos_code shockPos_Experienced shockPos_month shockPos_year shockPos_value  shockPos_rank1 shockPos_rank2 shockPos_rank3, i(a01 year hid) j(act)
save "tmp_2015t2_male", replace



clear
use "BIHSRound3\Male\069_bihs_r3_male_mod_t2.dta"


gen year=2018
gen hid=int(a01)

rename t2_01 shockPos_code
rename t2_03 shockPos_Experienced
rename t2_04 shockPos_month
rename t2_05 shockPos_year
rename t2_06 shockPos_value
rename t2_07 shockPos_rank

replace shockPos_Experienced = abs(2-shockPos_Experienced)


#delimit ;
keep year hid a01 shockPos_code-shockPos_rank hh_type
;
#delimit cr

g shockPos_rank1 = (shockPos_rank==1)
g shockPos_rank2 = (shockPos_rank==2)
g shockPos_rank3 = (shockPos_rank==3)

label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"

label var shockPos_code "Positive shock: shock code"
label var shockPos_Experienced "Positive shock: Has any events (last 5 years)"
label var shockPos_month "Positive shock: (The last time) Month"
label var shockPos_year "Positive shock: (The last time) Year"
label var shockPos_value "Positive shock: (The last time) total value"
label var shockPos_rank "Positive shock: Rank the most important events"
label var shockPos_rank1 "Positive shock: most important events"
label var shockPos_rank2 "Positive shock: 2nd most important events"
label var shockPos_rank3 "Positive shock: 3rd most important events"

drop shockPos_rank

by a01 , sort: gen act=_n
reshape wide shockPos_code shockPos_Experienced shockPos_month shockPos_year shockPos_value  shockPos_rank1 shockPos_rank2 shockPos_rank3, i(a01 year hid) j(act)
save "tmp_2018t2_male", replace


clear
use "BIHSRound3\Male\070_bihs_r3_male_mod_u.dta"

gen year=2018
gen hid=int(a01)

rename slno safetynet_SerialNo
rename u01 safetynet_assitance
rename u_mid1 safetynet_mid1
rename u_mid2 safetynet_mid2
rename u02 safetynet_cashreceived
rename u03 safetynet_riceKG
rename u04 safetynet_riceValue
rename u05 safetynet_wheatKG
rename u06 safetynet_wheatValue
rename u07 safetynet_otherfoodValue
rename u08 safetynet_othergoodValue

replace safetynet_assitance = abs(2-safetynet_assitance)

label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var safetynet_mid1 "Member Identification Number 1"
label var safetynet_mid2 "Member Identification Number 2"


#delimit ;
keep year hid a01 safetynet_SerialNo-safetynet_otherfoodValue safetynet_othergoodValue hh_type
;
#delimit cr
drop slnooth
by a01 , sort: gen act=_n
reshape wide safetynet_SerialNo safetynet_assitance safetynet_mid1 safetynet_mid2 safetynet_cashreceived safetynet_riceKG safetynet_riceValue safetynet_wheatKG safetynet_wheatValue safetynet_otherfoodValue safetynet_othergoodValue, i(a01 year hid) j(act)

save "tmp_2018u_male", replace


clear
use "BIHSRound3\Male\072_bihs_r3_male_mod_v1.dta"

gen year=2018
gen hid=int(a01)
rename mid migrants_mid

rename v1_01 Migrants_since2011
rename v1_02 Migrants_relation
rename v1_03 Migrants_year
rename v1_04 Migrants_month
rename v1_05 Migrants_age
rename v1_06 Migrants_sex
rename v1_07 Migrants_education
rename v1_08 Migrants_occupation
rename v1_09 Migrants_whichcountry
rename v1_10 Migrants_zilacode
rename v1_11 Migrants_countrycode
rename v1_12 Migrants_purpose
rename v1_13 Migrants_expense
rename v1_14 Migrants_remittance
rename v1_15 Migrants_helper

label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var migrants_mid "Member Identification Number"

#delimit ;
keep year hid a01 Migrants_since2011-Migrants_helper Migrants_purpose- Migrants_remittance hh_type
;
#delimit cr

by a01 , sort: gen act=_n
reshape wide Migrants_since2011 pid migrants_mid Migrants_relation Migrants_year Migrants_month Migrants_age Migrants_sex Migrants_education Migrants_occupation Migrants_whichcountry Migrants_zilacode Migrants_countrycode Migrants_helper Migrants_purpose Migrants_expense Migrants_remittance, i(a01 year hid) j(act)
save "tmp_2018v1_male", replace




clear
use "BIHSRound3\Male\073_bihs_r3_male_mod_v2.dta"

gen year=2018
gen hid=int(a01)
rename mid_v2 migrants_mid

rename v2_01 RemittanceIn_received
rename v2_02 RemittanceIn_relation
rename v2_03 RemittanceIn_withBangladesh
rename v2_04 RemittanceIn_outsideBangladesh
rename v2_05 RemittanceIn_nopayments
rename v2_06 RemittanceIn_totalmoney
rename v2_08a RemittanceIn_relievedactivity1
rename v2_08b RemittanceIn_relievedactivity2
rename v2_08c RemittanceIn_relievedactivity3
rename v2_09 RemittanceIn_anycondition
rename v2_10a RemittanceIn_item1
rename v2_10b RemittanceIn_item2
rename v2_10c RemittanceIn_item3
rename v2_11 RemittanceIn_senttowhom


label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var migrants_mid "Member Identification Number"

#delimit ;
keep year hid a01 RemittanceIn_relation- RemittanceIn_totalmoney RemittanceIn_relievedactivity1- RemittanceIn_senttowhom hh_type
;
#delimit cr

by a01 , sort: gen act=_n
reshape wide RemittanceIn_relation RemittanceIn_withBangladesh RemittanceIn_outsideBangladesh RemittanceIn_nopayments RemittanceIn_totalmoney RemittanceIn_relievedactivity1 RemittanceIn_relievedactivity2 RemittanceIn_relievedactivity3 RemittanceIn_anycondition RemittanceIn_item1 RemittanceIn_item2 RemittanceIn_item3 RemittanceIn_senttowhom    , i(a01 year hid) j(act)
sort a01 hid
save "tmp_2018v2_1_male", replace



clear
use "BIHSRound3\Male\074_bihs_r3_male_mod_v2_12.dta"

gen year=2018
gen hid=int(a01)

rename v2_12_1 RemittanceIn_usedfor_Aborad1
rename v2_12_2 RemittanceIn_usedfor_Aborad2
rename v2_12_3 RemittanceIn_usedfor_Aborad3
rename v2_13_1 RemittanceIn_usedfor_Bangla1
rename v2_13_2 RemittanceIn_usedfor_Bangla2
rename v2_13_3 RemittanceIn_usedfor_Bangla3

by a01 , sort: gen act=_n
reshape wide  RemittanceIn_usedfor_Aborad1 RemittanceIn_usedfor_Aborad2 RemittanceIn_usedfor_Aborad3 RemittanceIn_usedfor_Bangla1 RemittanceIn_usedfor_Bangla2 RemittanceIn_usedfor_Bangla3  , i(a01 year hid) j(act)
sort a01 hid
save "tmp_2018v2_2_male", replace


clear
use "tmp_2018v2_1_male"
sort a01 hid
merge a01 hid using "tmp_2018v2_2_male"
drop _merge

save "tmp_2018v2_male", replace


clear
use "BIHSRound3\Male\075_bihs_r3_male_mod_v3.dta"

gen year=2018
gen hid=int(a01)

rename v3_01 RemittanceOut_Send
rename v3_sl RimittanceOut_SerialNo
rename v3_02 RemittanceOut_relation
rename v3_03 RemittanceIn_withBangladesh
rename v3_04 RemittanceIn_outsideBangladesh
rename v3_05 RemittanceIn_nopayments
rename v3_06 RemittanceIn_totalmoney


#delimit ;
keep year hid a01 RemittanceOut_Send-RemittanceIn_totalmoney  hh_type
;
#delimit cr
label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"

by a01 , sort: gen act=_n
reshape wide RemittanceOut_Send RimittanceOut_SerialNo RemittanceOut_relation RemittanceIn_withBangladesh RemittanceIn_outsideBangladesh RemittanceIn_nopayments RemittanceIn_totalmoney, i(a01 year hid) j(act)
save "tmp_2018v3_male", replace


clear
use "BIHSRound3\Male\076_bihs_r3_male_mod_v4.dta"

gen year=2018
gen hid=int(a01)

rename v4_01 inc_landrent
rename v4_02 inc_otherrent
rename v4_03 inc_insurance
rename v4_04 inc_stock
rename v4_05 inc_retirement
rename v4_06 inc_lottery_cash
rename v4_07 inc_lottery_kind
rename v4_08 inc_charity_cash
rename v4_09 inc_charity_kind
rename v4_10 inc_interest
rename v4_11 inc_other_cash
rename v4_12 inc_other_kind

label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"

#delimit ;
keep year hid a01 inc_landrent-inc_other_kind hh_type
;
#delimit cr

save "tmp_2018v4_male", replace


clear
use "BIHSRound3\Female\101_bihs_r3_female_mod_w3.dta"

gen year=2018
gen hid=int(a01)
rename mid_w3 mid
rename w3_01 health_standup
rename w3_02 health_walk
rename w3_03 health_carry
rename w3_04 health_hearing
rename w3_05 health_speaking
rename w3_06 health_eyesight
rename w3_07 health_limg
rename w3_08 health_sensetouch
drop w3_07oth w3_08oth

label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var mid "Member Identification Number"

#delimit ;
keep year hid a01 mid  health_standup-health_sensetouch hh_type
;
#delimit cr

save "tmp_2018w3_female", replace



clear
use "BIHSRound3\Female\102_bihs_r3_female_mod_w4.dta"

gen year=2018
gen hid=int(a01)

rename mid_w4 mid
rename w4_01 illness
rename w4_02 illness_dur
rename w4_03 illness_dur_over15years
rename w4_04 illness_weightloss
rename w4_05 illness_fever
rename w4_06 illness_fever_dur
rename w4_07 illness_diarrhoea
rename w4_08 illness_diarrhoea_dur
rename w4_09 illness_cough
rename w4_10 illness_cough_dur
rename w4_11 illness_skin
rename w4_12 illness_skin_dur
rename w4_13 illness_infection
rename w4_14 illness_infection_dur


#delimit ;
keep year hid a01 mid illness-illness_infection_dur  hh_type
;
#delimit cr
label var hh_type "type of sample survey"
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var mid "Member Identification Number"

save "tmp_2018w4_female", replace



*Module Z: Women's Status
*Module Z1: Work Earnings and Expenses




clear
use "BIHSRound3\Female\121_bihs_r3_female_mod_z1.dta"

gen year=2018
gen hid=int(a01)

rename z_1 mid
rename z_2 maritalstatus

g working = (z1_01==1)
rename z1_02 whynotworking
rename z1_03 whynotworking_familyissue

g working_familyallow = (z1_04==1)
g workathome = (z1_05==1)
g workoutside = (z1_05==2)
g workboth_homeoutside = (z1_05==3)

rename z1_06 working_decisionmaker
rename z1_07 familysupport
rename z1_08 familysupport_whyyes
rename z1_09 familysupport_whynot

g giveallmoneytohome = (z1_10==1)
g givesomemoneytohome = (z1_10==2)
g keepmoney = (z1_10==3)

g spendingdecision_wife = (z1_11==1)
g spendingdecision_husband = (z1_11==2)
g spendingdecision_together = (z1_11==3)
g spendingdecision_someone = (z1_11==4)

g loanNGO = (z1_12==1)

rename z1_13 loanNGO_decisionmaker
rename z1_14 loanNGO_decisionmaker_spending

rename z1_15a decisionmaker_food
rename z1_15b decisionmaker_housing
rename z1_15c decisionmaker_healthcare
rename z1_15d decisionmaker_education
rename z1_15e decisionmaker_clothing

rename z1_16a controlherself_food
rename z1_16b controlherself_clothing
rename z1_16c controlherself_medicine
rename z1_16d controlherself_cosmetics
drop z1_06oth z1_08oth z1_13oth z1_14oth z1_15aoth z1_15both z1_15coth z1_15doth z1_15eoth
#delimit ;
keep year hid a01 mid maritalstatus working whynotworking whynotworking_familyissue working_decisionmaker- familysupport_whynot loanNGO_decisionmaker- controlherself_medicine  controlherself_cosmetics hh_type 
;
#delimit cr
label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var mid "Member Identification Number"
label var hh_type "type of sample survey"

label var whynotworking "Reason for not working"
label var whynotworking_familyissue "Reason for not working: Family issue"
label var working_decisionmaker "Who make a decision to work"
label var familysupport "Family member ask you not to work"
label var familysupport_whyyes "Family member ask you not to work, why"
label var familysupport_whynot "Family member ask you not to work, why not"
label var loanNGO_decisionmaker "Who make a decision to take the loan from the NGO"
label var loanNGO_decisionmaker_spending "Who make a decision to spend the money from NGO"
label var decisionmaker_food "Who make a decision: Food"
label var decisionmaker_housing  "Who make a decision: Housing"
label var decisionmaker_healthcare  "Who make a decision: Health care"
label var decisionmaker_education  "Who make a decision: Education"
label var decisionmaker_clothing  "Who make a decision: Clothing"
label var controlherself_food "Do you yourself contol the money: Food"
label var controlherself_clothing "Do you yourself contol the money: Clothing"
label var controlherself_medicine "Do you yourself contol the money: Medicine"
label var controlherself_cosmetics "Do you yourself contol the money: Cosmetics"

save "tmp_2018z1_female", replace




*Module Z3: Reproductive Decisions

clear
use "BIHSRound3\Female\123_bihs_r3_female_mod_z3.dta"


gen year=2018
gen hid=int(a01)

rename z3_mid mid

rename z3_01 birthcontrol
rename z3_01a birthcontrol_method
rename z3_02 birthcontrol_decisionmaker
rename z3_03 birthcontrol_whynot1
rename z3_03oth birthcontrol_whynot2
rename z3_04 birthcontrol_husband
rename z3_04a birthcontrol_husband_method
rename z3_05 sterilized_man
rename z3_06 sterilized_woman

label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var hh_type "type of sample survey"

label var birthcontrol "Have you ever used birth control"
label var birthcontrol_decisionmaker "Who make birth control decision"
label var birthcontrol_husband "Has your husband ever used birth control"
label var sterilized_man "Is the man sterilized?"
label var sterilized_woman "Is the woman sterilized?"
drop z3_01aoth z3_02oth z3_consent z3_04aoth
#delimit ;
keep year hid a01 birthcontrol-sterilized_woman hh_type   mid
;
#delimit cr

save "tmp_2018z3_female", replace


*Module Z4: Domestic Violence, Abuse and Threats 


clear
use "BIHSRound3\Female\124_bihs_r3_female_mod_z4.dta"


gen year=2018
gen hid=int(a01)

rename z4_mid mid

rename z4_01a threaten_divorce
rename z4_01b threaten_anotherwife
rename z4_01c1 abuse_verbally
rename z4_01c2 abuse_verbally_anothermale
rename z4_01c3 abuse_verbally_anotherfemale
rename z4_01d1 abuse_physically
rename z4_01d2 abuse_physically_anothermale
rename z4_01d3 abuse_physically_anotherfemale
rename z4_02 wanttoleave
rename z4_03 leave
rename z4_04 leave_whynot
rename z4_05 leave_threat
rename z4_06 leave_force
rename z4_07 leave_whobroughtback
rename z4_08 leave_whycombackbyyourself
rename z4_09 hus_alcohol
rename z4_10 hus_drug

label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var hh_type "type of sample survey"
drop z4_01e1a z4_01e1b z4_01e1c z4_01e2a z4_01e2b z4_01e2c z4_01e3a z4_01e3b z4_01e3c z4_09a z4_10a
#delimit ;
keep year hid a01 threaten_divorce-hus_drug hh_type  mid
;
#delimit cr
label var wanttoleave "If your husband or family member threat or abuse you, did you want to leave?"

save "tmp_2018z4_female", replace



*Module WE

clear
use "BIHSRound3\Female\126_bihs_r3_female_weai_ind_mod_wa.dta"
gen year=2018
gen hid=int(a01)

rename wa03 mid
keep year hid mid a01
save "tmp_2018wa_female", replace

clear
use "BIHSRound3\Female\127_bihs_r3_female_weai_ind_mod_we2.dta"
gen year=2018
gen hid=int(a01)

rename we2_01_1 foodcrop
rename we2_02_1 foodcropdecision
rename we2_03_1 foodcropincome
rename we2_01_2 cashcrop
rename we2_02_2 cashcropdecision
rename we2_03_2 caashcropincome
rename we2_01_31 largelivestock
rename we2_02_31 largelivestockdecision
rename we2_03_31 largelivestockincome
rename we2_01_32 smalllivestock
rename we2_02_32 smalllivestockdecision
rename we2_03_32 smalllivestockincome
rename we2_01_33 poultry
rename we2_02_33 poultrydecision
rename we2_03_33 poultrykincome
rename we2_01_4 nonfarmact
rename we2_02_4 nonfarmactdecision
rename we2_03_4 nonfarmactkincome
rename we2_01_5 wageemployment
rename we2_02_5 wageemploymentdecision
rename we2_03_5 wageemploymenttkincome
rename we2_01_6 fishing
rename we2_02_6 fishingdecision
rename we2_03_6 fishingtkincome
drop hhid2 hh_type round
save "tmp_2018we2_female", replace

clear
use "BIHSRound3\Female\130_bihs_r3_female_weai_ind_mod_we3c.dta"
gen year=2018
gen hid=int(a01)

rename we3c_11 havemoneytospend
keep year hid a01 havemoneytospend 
save "tmp_2018wc3_female", replace


clear
use "BIHSRound3\Female\131_bihs_r3_female_weai_ind_mod_we3d.dta"
gen year=2018
gen hid=int(a01)
rename we3d_17a loanfromngo
rename we3d_18a_a loanfromngodecsion1
rename we3d_18b_a loanfromngodecsion2
rename we3d_18c_a loanfromngodecsion3
rename we3d_19a_a loanfromngousedecision1
rename we3d_19b_a loanfromngousedecision2
rename we3d_19c_a loanfromngousedecision3

rename we3d_17b loanfrominformal
rename we3d_18a_b loanfrominformaldecsion1
rename we3d_18b_b loanfrominformaldecsion2
rename we3d_18c_b loanfrominformaldecsion3
rename we3d_19a_b loanfrominformalusedecision1
rename we3d_19b_b loanfrominformalusedecision2
rename we3d_19c_b loanfrominformalusedecision3

rename we3d_17c loanfromformal
rename we3d_18a_c loanfromformaldecsion1
rename we3d_18b_c loanfromformaldecsion2
rename we3d_18c_c loanfromformaldecsion3
rename we3d_19a_c loanfromformalusedecision1
rename we3d_19b_c loanfromformalusedecision2
rename we3d_19c_c loanfromformalusedecision3

rename we3d_17d loanfromfriend
rename we3d_18a_d loanfromfrienddecsion1
rename we3d_18b_d loanfromfrienddecsion2
rename we3d_18c_d loanfromfrienddecsion3
rename we3d_19a_d loanfromfriendusedecision1
rename we3d_19b_d loanfromfriendusedecision2
rename we3d_19c_d loanfromfriendusedecision3

rename we3d_17e loanfromnoninsti
rename we3d_18a_e loanfromnoninstidecsion1
rename we3d_18b_e loanfromnoninstidecsion2
rename we3d_18c_e loanfromnoninstidecsion3
rename we3d_19a_e loanfromnoninstiusedecision1
rename we3d_19b_e loanfromnoninstiusedecision2
rename we3d_19c_e loanfromnoninstiusedecision3

drop hhid2 hh_type round
save "tmp_2018we3d_female", replace


clear
use "BIHSRound3\Female\132_bihs_r3_female_weai_ind_mod_we4.dta"
gen year=2018
gen hid=int(a01)
keep a01 we4_01 we4_02 we4_03 we4_04 year hid we4_06
rename we4_01 speakingupinfra
rename we4_02 speakinguppayment
rename we4_03 speakingupprotest
rename we4_04 canchangecommunity
rename we4_06 influential
save "tmp_2018we4_female", replace


clear
use "BIHSRound3\Female\133_bihs_r3_female_weai_ind_mod_we5a.dta"
gen year=2018
gen hid=int(a01)
rename we5a_01a_a buyforagricultural1
rename we5a_01a_b typesofcrops1
rename we5a_01a_c cropstomarket1
rename we5a_01a_d livestockraising1
rename we5a_01a_e ownwagesalary1
rename we5a_01a_f majorhouseexp1
rename we5a_01a_g minorhouseexp1

rename we5a_01b_a buyforagricultural2
rename we5a_01b_b typesofcrops2
rename we5a_01b_c cropstomarket2
rename we5a_01b_d livestockraising2
rename we5a_01b_e ownwagesalary2
rename we5a_01b_f majorhouseexp2
rename we5a_01b_g minorhouseexp2

rename we5a_01c_a buyforagricultural3
rename we5a_01c_b typesofcrops3
rename we5a_01c_c cropstomarket3
rename we5a_01c_d livestockraising3
rename we5a_01c_e ownwagesalary3
rename we5a_01c_f majorhouseexp3
rename we5a_01c_g minorhouseexp3
keep a01- minorhouseexp3 hid year
save "tmp_2018we5a_female", replace


clear
use "BIHSRound3\Female\135_bihs_r3_female_weai_ind_mod_we5c.dta"
gen year=2018
gen hid=int(a01)
rename we5c_03_a avoidpunishment_nonfarm
rename we5c_03_b avoidpunishment_ownwage
rename we5c_03_c avoidpunishment_minorexp
rename we5c_03_d avoidpunishment_health
rename we5c_03_e avoidpunishment_violence
rename we5c_03_f avoidpunishment_religious
rename we5c_03_g avoidpunishment_tasks
rename we5c_03_h avoidpunishment_limitbirth


rename we5c_04_a aviodblame_nonfarm
rename we5c_04_b aviodblame_ownwage
rename we5c_04_c aviodblame_minorexp
rename we5c_04_d aviodblame_health
rename we5c_04_e aviodblame_violence
rename we5c_04_f aviodblame_religious
rename we5c_04_g aviodblame_tasks
rename we5c_04_h aviodblame_limitbirth

rename we5c_05_a owninterests_nonfarm
rename we5c_05_b owninterests_ownwage
rename we5c_05_c owninterests_minorexp
rename we5c_05_d owninterests_health
rename we5c_05_e owninterests_violence
rename we5c_05_f owninterests_religious
rename we5c_05_g owninterests_tasks
rename we5c_05_h owninterests_limitbirth


rename we5c_06_a satisfaction_nonfarm
rename we5c_06_b satisfaction_ownwage
rename we5c_06_c satisfaction_minorexp
rename we5c_06_d satisfaction_health
rename we5c_06_e satisfaction_violence
rename we5c_06_f satisfaction_religious
rename we5c_06_g satisfaction_tasks
rename we5c_06_h satisfaction_limitbirth

drop hhid2 hh_type round
save "tmp_2018we5c_female", replace

clear
use "tmp_2018wa_female"
merge 1:1 a01 using "tmp_2018we2_female"
drop _merge
merge 1:1 a01 using "tmp_2018wc3_female"
drop _merge
merge 1:1 a01 using "tmp_2018we3d_female"
drop _merge
merge 1:1 a01 using "tmp_2018we4_female"
drop _merge
merge 1:1 a01 using "tmp_2018we5a_female"
drop _merge
merge 1:1 a01 using "tmp_2018we5c_female"
drop _merge
save "tmp_2018we_merge", replace



*Module WE7


clear
use "BIHSRound3\Male\078_bihs_r3_male_weai_ind_mod_wa.dta"
gen year=2018
gen hid=int(a01)

rename wa03 mid
keep year hid mid a01
save "tmp_2018wea_male", replace

clear
use "BIHSRound3\Male\090_bihs_r3_male_weai_ind_mod_we7b.dta"
gen year=2018
gen hid=int(a01)
keep year hid  a01 we7b_1 we7b_2 we7b_5
merge 1:1 a01 using "tmp_2018wea_female"
keep if _merge==3
drop _merge
rename we7b_1 mothereduM
rename we7b_2 fathereduM
rename we7b_5 whereyoubornM
save "tmp_2018we7_male", replace

clear
use "BIHSRound3\Female\126_bihs_r3_female_weai_ind_mod_wa.dta"
gen year=2018
gen hid=int(a01)

rename wa03 mid
keep year hid mid a01
save "tmp_2018wea_female", replace

clear
use "BIHSRound3\Female\138_bihs_r3_female_weai_ind_mod_we7b.dta"
gen year=2018
gen hid=int(a01)
keep year hid  a01 we7b_1 we7b_2 we7b_5
merge 1:1 a01 using "tmp_2018wea_female"
keep if _merge==3
drop _merge
rename we7b_1 mothereduF
rename we7b_2 fathereduF
rename we7b_5 whereyoubornF
save "tmp_2018we7_female", replace

*Module Z5:  Wife’s Assets that had been brought to Marriage 



clear
use "BIHSRound3\Female\125_bihs_r3_female_mod_z5.dta"

gen year=2018
gen hid=int(a01)

rename res_id_z5 mid

rename z5_01 assetformarriage
rename z5_02  assetformarriage_assetcode
rename z5_03 assetformarriage_value

label var year "2011-2012, 2015, 2018"
label var a01 "Household identification number"
label var hh_type "type of sample survey"

#delimit ;
keep year hid a01 assetformarriage-assetformarriage_value hh_type mid
;
#delimit cr

sort a01
by a01: egen assetformarriage_valuesum = sum(assetformarriage_value)
replace assetformarriage_value = assetformarriage_valuesum
keep a01 hh_type assetformarriage_value year hid mid
duplicates drop
/*
by a01 , sort: gen act=_n
reshape wide assetformarriage assetformarriage_assetcode assetformarriage_value, i(a01 year hid) j(act)
*/
save "tmp_2018z5_female", replace

**************************************
*Module XXa, XXb, and XXc in 2018
**************************************
use "BIHSRound3\Female\093_bihs_r3_female_mod_xxc.dta", clear
gen year=2018
gen hid=int(a01)
rename res_id_xxc mid
drop if mid==.
drop stime_* etime_* hhid2 round hh_type
sort a01 mid
save "tmp_2018xxc", replace

use "BIHSRound3\Female\094_bihs_r3_female_mod_xxa.dta", clear

gen rf_marriage=1
label var rf_marriage "returned from marriage"

gen year=2018
gen hid=int(a01)
rename xxa_mid mid

rename xxa_01 hage
rename xxa_02 page
rename xxa_03 ceducation
rename xxa_04 meducation
rename xxa_05 hceducation
rename xxa_06 hmeducation
rename xxa_07 cmage
rename xxa_08 feduc
rename xxa_09 meduc
rename xxa_10 falive
rename xxa_11 focc
rename xxa_12 malive
rename xxa_13 nb_marriage
rename xxa_14 ns_marriage
rename xxa_15a dowry_paid
rename xxa_15b dowry_gold
rename xxa_15c dowry_inkind
rename xxa_16 mahr_promised
rename xxa_17a mahr_paid
rename xxa_17b mahr_gold
rename xxa_17c mahr_inkind

rename xxa_18a cm_reason1
rename xxa_18b cm_reason2
rename xxa_18c cm_reason3

drop if xxa_slno==0
drop if mid==.

*We only keep observations who are the target of the module

#delimit ;

keep rf_marriage year hid a01 mid hage page ceducation meducation hceducation hmeducation cmage
feduc meduc falive focc malive nb_marriage ns_marriage dowry_paid
dowry_gold dowry_inkind mahr_promised mahr_paid mahr_gold mahr_inkind
cm_reason1 cm_reason2 cm_reason3
;
#delimit cr

sort a01 mid
save "tmp_2018xxa", replace

use "BIHSRound3\Female\095_bihs_r3_female_mod_xxb.dta", clear

gen rf_marriage=1
label var rf_marriage "returned from marriage"

gen year=2018
gen hid=int(a01)
rename xxb_mid mid

rename xxb_01 hage
rename xxb_02 page
rename xxb_03 ceducation
rename xxb_04 meducation
rename xxb_05 hceducation
rename xxb_06 hmeducation
rename xxb_07 cmage
rename xxb_08 feduc
rename xxb_09 meduc
rename xxb_10 falive
rename xxb_11 focc
rename xxb_12 malive
rename xxb_13 nb_marriage
rename xxb_14 ns_marriage
rename xxb_15a dowry_paid
rename xxb_15b dowry_gold
rename xxb_15c dowry_inkind
rename xxb_16 mahr_promised
rename xxb_17a mahr_paid
rename xxb_17b mahr_gold
rename xxb_17c mahr_inkind

rename xxb_18a cm_reason1
rename xxb_18b cm_reason2
rename xxb_18c cm_reason3

drop if mid==0
drop if mid==.
*We only keep observations who are the target of the module

#delimit ;

keep rf_marriage year hid a01 mid hage page ceducation meducation hceducation hmeducation cmage
feduc meduc falive focc malive nb_marriage ns_marriage dowry_paid
dowry_gold dowry_inkind mahr_promised mahr_paid mahr_gold mahr_inkind
cm_reason1 cm_reason2 cm_reason3
;
#delimit cr

sort a01 mid
save "tmp_2018xxb", replace

append using "tmp_2018xxa"
save "tmp_2018xxab", replace

*Education variables cleaning

gen myrsedu=.
replace myrsedu=0 if meducation==99 | meducation==66 | meducation==67 
replace myrsedu=1 if meducation==0 | meducation==1
replace myrsedu=2 if meducation==2
replace myrsedu=3 if meducation==3
replace myrsedu=4 if meducation==4
replace myrsedu=5 if meducation==5
replace myrsedu=6 if meducation==6
replace myrsedu=7 if meducation==7
replace myrsedu=8 if meducation==8
replace myrsedu=9 if meducation==9
replace myrsedu=10 if meducation==10
replace myrsedu=12 if meducation==12

replace myrsedu=16 if meducation==14 | meducation==15 | meducation==72 | meducation==73 | meducation==74
replace myrsedu=18 if meducation==16 | meducation==71 
replace myrsedu=10 if meducation==22
replace myrsedu=12 if meducation==33 | meducation==75

gen hmyrsedu=.
replace hmyrsedu=0 if hmeducation==99 | hmeducation==66 | hmeducation==67 
replace hmyrsedu=1 if hmeducation==0 | hmeducation==1
replace hmyrsedu=2 if hmeducation==2
replace hmyrsedu=3 if hmeducation==3
replace hmyrsedu=4 if hmeducation==4
replace hmyrsedu=5 if hmeducation==5
replace hmyrsedu=6 if hmeducation==6
replace hmyrsedu=7 if hmeducation==7
replace hmyrsedu=8 if hmeducation==8
replace hmyrsedu=9 if hmeducation==9
replace hmyrsedu=10 if hmeducation==10
replace hmyrsedu=12 if hmeducation==12

replace hmyrsedu=16 if hmeducation==14 | hmeducation==15 | hmeducation==72 | hmeducation==73 | hmeducation==74
replace hmyrsedu=18 if hmeducation==16 | hmeducation==71 
replace hmyrsedu=10 if hmeducation==22
replace hmyrsedu=12 if hmeducation==33 | hmeducation==75

gen fyrsedu=.
replace fyrsedu=0 if feduc==99 | feduc==66 | feduc==67 
replace fyrsedu=1 if feduc==0 | feduc==1
replace fyrsedu=2 if feduc==2
replace fyrsedu=3 if feduc==3
replace fyrsedu=4 if feduc==4
replace fyrsedu=5 if feduc==5
replace fyrsedu=6 if feduc==6
replace fyrsedu=7 if feduc==7
replace fyrsedu=8 if feduc==8
replace fyrsedu=9 if feduc==9
replace fyrsedu=10 if feduc==10
replace fyrsedu=12 if feduc==12

replace fyrsedu=16 if feduc==14 | feduc==15 | feduc==72 | feduc==73 | feduc==74
replace fyrsedu=18 if feduc==16 | feduc==71 
replace fyrsedu=10 if feduc==22
replace fyrsedu=12 if feduc==33 | feduc==75

gen moyrsedu=.
replace moyrsedu=0 if meduc==99 | meduc==66 | meduc==67 
replace moyrsedu=1 if meduc==0 | meduc==1
replace moyrsedu=2 if meduc==2
replace moyrsedu=3 if meduc==3
replace moyrsedu=4 if meduc==4
replace moyrsedu=5 if meduc==5
replace moyrsedu=6 if meduc==6
replace moyrsedu=7 if meduc==7
replace moyrsedu=8 if meduc==8
replace moyrsedu=9 if meduc==9
replace moyrsedu=10 if meduc==10
replace moyrsedu=12 if meduc==12

replace moyrsedu=16 if meduc==14 | meduc==15 | meduc==72 | meduc==73 | meduc==74
replace moyrsedu=18 if meduc==16 | meduc==71 
replace moyrsedu=10 if meduc==22
replace moyrsedu=12 if meduc==33 | meduc==75

label var myrsedu "women's education at the time of marriage"
label var hmyrsedu "husband's education at the time of marriage"
label var fyrsedu "women's father's education (in years)"
label var moyrsedu "women's mother's education (in years)"

save "tmp_2018xxab", replace


